<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
  <style>
    #user1,#password1{
     display:none;
     }
  </style>
</head>
<body>
  <div class="login">
    <form class="login-wrap btnLogin">
      <img class="avatar" src="../assets/img/default.png">
      <!-- 错误信息时展示 -->
      <div class="alert alert-danger" id="user1">
        <span class="user">邮箱错误请重新输入</span>
    </div>
    <div class="alert alert-danger" id="password1">
      <span class="user">密码错误请重新输入</span>
  </div>
      <div class="form-group">
        <label for="email" class="sr-only">邮箱</label>
        <input id="email" type="email" name='email' class="form-control" placeholder="邮箱" autofocus value="w@zce.me">
      </div>
      <div class="form-group">
        <label for="password" class="sr-only">密码</label>
        <input id="password" type="password" name='password' class="form-control" placeholder="密码" value="wanglei">
      </div>
      <a class="btn btn-primary btn-block" href="javascript:;">登 录</a>
    </form>
  </div>
  <!-- //引入jquery文件 -->
  <script src="../assets/vendors/jquery/jquery.js"></script>
  <script>
     //为登录按钮注册点击事件
     $('.btn').on('click',function(){
         //给邮箱一个正确的格式，如果不正确则提示用户格式错误
         let email =$('#email').val()
         if(!/\w+[@]\w+[.]\w+/.test(email)){
              //将错误结果显示到页面让用户知道
           return  $('#user1').fadeIn(1100).delay(2000).fadeOut(1100)
         }
         let password = $('#password').val().trim().length
        //  console.log(password)
         if(password<6||password>12){
              //将错误结果显示到页面让用户知道
              return $('#password1').fadeIn(1100).delay(2000).fadeOut(1100)
         }
         //如果邮箱和密码都正确则发送ajax请求
         $.ajax({
            type:'post',
            url:'/login',
            data:$('form').serialize(),
            dataType:'json',
            success:function(res){
               if(res.code==200){
                location.href='/admin/index'
               }
            }
         })
     })
  </script>
  
</body>
</html>
